#! /usr/bin/python
from math import sqrt
from math import floor

def is_prime(n):
  if n == 2 or n == 3: return True
  if n < 2 or n%2 == 0: return False
  if n < 9: return True
  if n%3 == 0: return False
  r = int(n**.5)
  f = 5
  while f <= r:
    if n%f == 0: return False
    if n%(f+2) == 0: return False
    f +=6
  return True

for d in range(999, 1, -2):
  if not is_prime(d): continue
  c = 1
  while (pow(10, c) - 1) % d != 0:
    c += 1
  if (d-c) == 1: break
print "Answer to PE26 = ",d
